package com.rp.system.corn.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rp.common.result.ResultDTO;
import com.rp.system.corn.entity.QuartzJob;
import com.rp.system.corn.service.JobService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@Slf4j
@RestController
@RequestMapping("/job")
@Api("定时任务")
public class JobController {

    @Autowired
    private JobService jobService;

	@PostMapping("/add")
	public ResultDTO save(QuartzJob quartz){
		log.info("新增任务");
		ResultDTO result = jobService.saveJob(quartz);
		return result;
	}

	@PostMapping("/edit")
	public ResultDTO edit(QuartzJob quartz){
		log.info("编辑任务");
		ResultDTO result = jobService.updateJob(quartz);
		return result;
	}
	@PostMapping("/list")
	public IPage list(String jobName, Integer pageNo, Integer pageSize){
		log.info("任务列表");
		IPage pageInfo = jobService.listQuartzJob(jobName, pageNo, pageSize);
		return pageInfo;
	}

	@PostMapping("/trigger")
	public  ResultDTO trigger(String jobName, String jobGroup) {
		log.info("触发任务");
		ResultDTO result = jobService.triggerJob(jobName, jobGroup);
		return result;
	}

	@PostMapping("/pause")
	public  ResultDTO pause(String jobName, String jobGroup) {
		log.info("停止任务");
		ResultDTO result = jobService.pauseJob(jobName, jobGroup);
		return result;
	}

	@PostMapping("/resume")
	public  ResultDTO resume(String jobName, String jobGroup) {
		log.info("恢复任务");
		ResultDTO result = jobService.resumeJob(jobName, jobGroup);
		return result;
	}

	@PostMapping("/remove")
	public  ResultDTO remove(String jobName, String jobGroup) {
		log.info("移除任务");
		ResultDTO result = jobService.removeJob(jobName, jobGroup);
        return result;
	}
}
